
package hasthi.manager.gui;

import java.util.Collection;
import java.util.List;
import java.util.Vector;

import hasthi.metamodel.resource.ManagedResource;

public class ResourceNode {
    public static enum NodeType{Service,ComputeNode,Host,TransientService,Domain,Parent,Root,Manager,Coordinator};
    
    private ManagedResource resource;
    private List<ResourceNode> children;
    private String name;
    private NodeType type;
    
    public ResourceNode(ManagedResource resource,NodeType type) {
        this.resource = resource;
        this.type = type;
        this.name = resource.getQName().getLocalPart();
    }
    public ResourceNode(String name,NodeType type) {
        this.name = name;
        this.type = type;
    }
    @Override
    public String toString() {
        return name + ( (children == null) ? "" : "(" + children.size() + ")") ;
    }
    
    public void addChild(ResourceNode node){
        if(children == null){
            children = new Vector<ResourceNode>();
        }
        children.add(node);
    }
    public Collection<ResourceNode> getChildren(){
        return children;
    }
    
    public void reset(){
        if(children != null){
            children.clear();
        }
    }
    
    public ResourceNode getChild(int index){
        return children.get(index);
    }
    
    public int getIndexOfChild(Object child) {
        return children.indexOf(child);
    }
    public ManagedResource getResource() {
        return resource;
    }
    
    public void setResource(ManagedResource resource) {
        this.resource = resource;
        this.name = resource.getQName().getLocalPart();
    }
    public NodeType getType() {
        return type;
    }
    
}

